home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir39 / 4derr210.zip / ON!ERROR.BTM < prev    next >
Text File  |  1994-09-22  |  5KB  |  131 lines

  1. @echo off
  2. rem  ON!ERROR.BTM -- 4Dos Error Handler Batch File for Unknown Commands.
  3. rem    Version 2.1, for 4DOS, version 5.0 or later.
  4. rem    Uses X.COM - K. Ledbetter's Command Archive eXecutive (Optional)
  5. rem    Created on 04/23/94 by STV    Last Revised on 09/22/94 by STV
  6. rem    ("::" - Indicates a Non-executing Code Line!)
  7.  
  8. rem {* Check The Version Of 4Dos Being Used *}
  9. if not %_4ver GE 5.0 (
  10.   *beep %+*echos    ERROR! --
  11.   *echo  Incorrect 4Dos version.
  12.   *echo    (The On!Error.Btm needs version 5 or later to run.)
  13.   cancel
  14. )
  15. rem {* Check For Enough Free Space In The Environment To Run *}
  16. if %_Env LT 128 (
  17.   *beep %+*echos    ERROR! --
  18.   *echo  4Dos environment space too small.
  19.   *echo    (The On!Error.Btm needs at least 128 bytes free to run.)
  20.   cancel
  21. )
  22. rem {* Give A Warning If This BTM Script Is Executed By User *}
  23. if %#==0 .or. "%1"=="/?" .or. "%@upper[%1]"=="/H" goto Warning
  24. rem {* Provide A Graceful Exit On A User Abort From This BTM Script *}
  25. rem - On a Ctrl-C (Ctrl-Break) execute the following before quitting.
  26. ON BREAK (
  27.   *beep 440 4 262 2
  28.   *scrput -2 1 bri magenta on %BgClr% [ User Abort! ]
  29.   goto Done
  30. )
  31. rem {* First Get The Unknown Command Line And Save It For Processing *}
  32. *set Unknown_CmdLine=%&
  33. rem {* Check To See If The The X.COM Program Is Present In The System *}
  34. rem - Search for the X.COM program along the defined search path to see if
  35. rem - it exists. If it does, then set the X-Path variable to point to it.
  36. *set X_Path=%@path[%@search[X.COM]]
  37. rem {* Get The Current Display's Background Screen Color *}
  38. *set BgClr=%_BG
  39. rem {* Check For Execptions Before Processing *}
  40. *set CmdError=Command Being Used Is Unknown!
  41. gosub Execptions
  42. rem - If the command library eXcutive (X.COM) doesn't exist in the system
  43. rem - then bypass the code to have it process the unknown command line.
  44. if "%X_Path%"=="" goto EditCmdLine
  45. rem - When wildcard characters are in the Command, don't run the X.COM program.
  46. if %@index[%CmdError%,Wildcard] GT -1 goto EditCmdLine
  47. rem - Have the command library eXcutive (X.COM) try to process the command
  48. rem - first. Alert the user by sound that the X.COM program is running.
  49. *beep 880 2
  50. @%X_Path%X %Unknown_CmdLine%
  51.   if errorlevel 1 goto UnknownError
  52.   if errorLevel 0 goto Done
  53. rem - If the command library eXcutive could not process it, then
  54. rem - show the Unknown Command to the user so it can be edited.
  55. :UnknownError
  56. *set CmdError=Unknown Command eXecutive Error!
  57. *echo.
  58. :EditCmdLine
  59. rem {* Inform The User That This BTM Script Is Running *}
  60. *color bri blue on %BgClr% %+*beep %+*echo.
  61. *echos    `>> 4DOS Error Handler Invoked:`
  62. *color red on %BgClr%
  63. *echo  %CmdError%
  64. *unset /q CmdError
  65. rem {* Now Give An Instructional Message *}
  66. *color bri yellow on %BgClr% %+*echo.
  67. *echo    Please correct the following Command Line for execution, or
  68. *echo    press [Esc] to delete it, and [Enter] to cancel execution:
  69. rem - Now show the user the bad command line.
  70. *color blink red on %BgClr% %+*echo.
  71. *echo  [ ERROR! ]
  72. *color cyan on %BgClr%
  73. *echos %@upper[%_Cwd]
  74. *color bri green on %BgClr%
  75. *echos ` >>`
  76. *color bri white on %BgClr%
  77. *input /e %%Unknown_CmdLine
  78. *scrput -2 1 red on %BgClr% [ ERROR! ]
  79. *color white on %BgClr%
  80. rem {* Now Process The Corrected Command Line *}
  81. rem - Place the corrected command in the history buffer.
  82. *history /a %Unknown_CmdLine%
  83. rem - Use a call, so we can properly handle batch files.
  84. call %Unknown_CmdLine%
  85. rem {* We're Done, So Clean Things Up Before Quiting *}
  86. :Done
  87. gosub CleanUp
  88. quit
  89.  
  90. rem {* Subroutines *}
  91. rem - This subroutine cleans up the 4Dos system before exiting this BTM script.
  92. :CleanUp
  93. rem - Reset the screen colors.
  94. *color white on %BgClr%
  95. rem - Remove any environment variables created for use by this BTM script.
  96. *unset /q BgClr
  97. *unset /q CmdError
  98. *unset /q Unknown_CmdLine
  99. *unset /q CmdVerb
  100. *unset /q X_Path
  101. return
  102.  
  103. rem - This subroutine examines the command verb of the Unknown Command
  104. rem - and then acts on certain execptions. Additional exceptions can be
  105. rem - added as the need arises.
  106. :Execptions
  107. rem - Get the Unknown command verb.
  108. *set CmdVerb=%@lower[%1]
  109. rem [ If the verb is 'Quit' or 'Cancel', then either quit or abort this script. ]
  110. if %@index[%CmdVerb%,quit] GT -1 goto Done
  111. if %@index[%CmdVerb%,cancel] GT -1 goto EndError
  112. rem [ If the verb is 'Else', 'Else(iff)', or 'Endiff', then abort this script. ]
  113. if %@index[%CmdVerb%,else] GT -1 .or. %@index[%CmdVerb%,end] GT -1 goto EndError
  114. rem [ If the verb contains a '*' or a '?' then gave an error msg about it. ]
  115. if %@index[%1,*] GT -1 .or. %@index[%1,?] GT -1 *set CmdError=Command Contains a Wildcard Character!
  116. rem - We're done here, so return for further processing.
  117. *unset /q CmdVerb
  118. return
  119. rem - We're ending on an error, so clean things up, and cancel all processing.
  120. :EndError
  121. gosub CleanUp
  122. cancel
  123.  
  124. rem {* Display A Warning Message To The User *}
  125. :Warning
  126. *echo ON!ERROR.BTM, vers. 2.1 (09/22/94)
  127. *echo On!Error -- Error handler for unknown commands in 4DOS.
  128. *beep %+echo. %+*color red on %_Bg
  129. *echo    Warning: "%@upper[%0]" is NOT an executable batch file!
  130. *color white on %_Bg
  131.